﻿using System.Collections.Generic;
using System.Linq;
using CoreLibrary;
using Entities;
using Entities.DataBase;
using Entities.DataBase.Obj;
using Entities.DataBase.Persistent;

namespace WebService {

    public class Settings {

        public static double Rate {
            get {
                return Util.GetDouble(GetSetting(SettingKey.Rate).Value, 0.0);
            }
        }

        public static double Balance {
            get {
                return Util.GetDouble(GetSetting(SettingKey.Balance).Value, 0.0);
            }
        }

        public static double RealRate {
            get {
                return Util.GetDouble(GetSetting(SettingKey.RealRate).Value, 0.0);
            }
        }


        public static Setting GetSetting(SettingKey key) {
            return GetSettings().SingleOrDefault(setting => setting.Name.Equals(key.Name));
        }

        public static List<Setting> GetSettings() {
            return Services.Locate<ISettingRepository>()
                           .GetAll();
        }

        
    }
}